/**
 * Created by zhangzhihao on 2016/12/06 11:00;
 */
var vm = new Vue({
	el : '#main',
	data : {
		taskId : App.getParam("taskId"),
		approve:{},
		approveData:{
			object:{},
		},
		url:''
	},
	created : function() {
		this.queryTaskNodeApprove();
		this.toexamine();
		var url = location.search;
		var url1 = url.split("&");
		var url2 = url1[1].split("=");
		var url3 = url2[1]   
		$("#vid").attr("src",url3);
		$("#video").attr("src",url3);
	},
	methods : {
        queryTaskNodeApprove:function(){
        	App.ajax({
    			type : "GET",
    			url : App.getApiUrl("queryTaskNodeApproveURL") + "?taskId="
    					+ this.taskId,
    			success : function(data) {
    				vm.approve = data;
    			}
    		});
        },
		bother:function(idx){
			var count = $("#ulto li").length;
			for(var i=0;i<=count;i++){
				if($("#li"+i).hasClass("toexa") == true){
					$("#li"+i).removeClass("toexa").addClass("tomine");
					$("#li"+idx).removeClass("tomine").addClass("toexa");
					$("#text").text("");
					$("#text").text($("#memo"+idx).text());
					if($("#state"+idx).text() == "2"){
						$("#tongguo").css({"background-color":"green","border-color":"green"});
						if($("#butongguo").css("background-color") == "rgb(255, 0, 0)"){
							$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
						}
					}else if($("#state"+idx).text()== "3"){
						$("#butongguo").css({"background-color":"red","border-color":"red"});
    					if($("#tongguo").css("background-color") == "rgb(0, 128, 0)"){
    						$("#tongguo").css({"background-color":"#dd514c",
    									"border-color":"#dd514c"
    									});
    					}
					}else{
							$("#tongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
							$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
					}
					this.anim();
					this.check($("#file"+idx).text());
					
				}
			}
		},
		next:function(){
			var count = $("#ulto li").length;
			for(var i=0;i<=count;i++){
				if($("#li"+i).hasClass("toexa") == true){
					$("#li"+i).removeClass("toexa").addClass("tomine");
					if((i+1) != 12){
						$("#li"+(i+1)).removeClass("tomine").addClass("toexa");
						$("#text").text("");
						$("#text").text($("#memo"+(i+1)).text());
						if($("#state"+(i+1)).text() == "2"){
							$("#tongguo").css({"background-color":"green","border-color":"green"});
							if($("#butongguo").css("background-color") == "rgb(255, 0, 0)"){
								$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
							}
						}else if($("#state"+(i+1)).text()== "3"){
							$("#butongguo").css({"background-color":"red","border-color":"red"});
	    					if($("#tongguo").css("background-color") == "rgb(0, 128, 0)"){
	    						$("#tongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
	    					}
						}else{
							$("#tongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
							$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
						}
						this.anim();
						this.check($("#file"+(i+1)).text());
						return;
					}else{
						$("#li0").removeClass("tomine").addClass("toexa");
						$("#text").text($("#memo0").text());
						if($("#state0").text() == "2"){
							$("#tongguo").css({"background-color":"green","border-color":"green"});
							if($("#butongguo").css("background-color") == "rgb(255, 0, 0)"){
								$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
							}
						}
						if($("#state0").text()== "3"){
							$("#butongguo").css({"background-color":"red","border-color":"red"});
	    					if($("#tongguo").css("background-color") == "rgb(0, 128, 0)"){
	    						$("#tongguo").css({"background-color":"#dd514c",
	    									"border-color":"#dd514c"
	    									});
	    					}
						}
						this.check($("#file0").text());
						return;
					}
				}
			}
		},
		//通过
		approveNode:function(_state){
			var _data = {};
			var count = $("#ulto li").length;
			for(var i=0;i<=count;i++){
				if($("#li"+i).hasClass("toexa") == true){
					_data.taskId = $("#task"+i).text();
					_data.nodeId = $("#node"+i).text();
					_data.approveId = $("#app"+i).text();
				}
			}
			if($("#text").val() == ""){
				_data.approveMemo = "null";
			}else{
				_data.approveMemo = $("#text").val();
			}
			_data.approveState = _state;
			if(_data.approveId==''){
				_data.approveId=0;
			}
			
			App.ajax({
    			type : "POST",
    			url : App.getApiUrl("saveNodeApproveURL"),
    			data:_data,
    			success : function(data) {
    				var ret = data.ret;
    				if(ret=='00000'){ //审核成功
    					if(_state == "2"){
    						$("#tongguo").css({"background-color":"green","border-color":"green"});
    						if($("#butongguo").css("background-color") == "rgb(255, 0, 0)"){
    							$("#butongguo").css({"background-color":"#dd514c","border-color":"#dd514c"});
    						}
    					};
    					if(_state == "3"){
    						/*$("#butongguo").css({"background-color":"red","border-color":"red"});
        					if($("#tongguo").css("background-color") == "rgb(0, 128, 0)"){
        						$("#tongguo").css({"background-color":"#dd514c",
        									"border-color":"#dd514c"
        									});
        					}*/
    						parent.showAlert(data.msg,function(){
                        		//window.location.reload();
    						});
    					}
    				}else{
    					parent.showAlert(data.msg);
    				}
    			}
    		});
    		
	    },
	    
        toexamine:function(){
        	App.ajax({
        		type : "GET",
    			url : App.getApiUrl("queryTaskNodeApproveURL") + "?taskId="
    					+ this.taskId,
    			success : function(data) {
    				vm.approve = data;
    				$("#touname").text(data.task.customerName);
    				$("#toutime").text(data.task.insuranceTime);
    				$("#toucode").text(data.task.cardCode);
    				$("#touhao").text(data.task.policyNo);
    				var url = location.search;
    				var url1 = url.split("&");
    				var url2 = url1[2].split("=");
    				var url3 = url2[1]-1;
    				var count = $("#ulto li").length;
    				for(var i=0;i<=count;i++){
    					if( (i) == url3){
    						$("#li"+i).removeClass("tomine").addClass("toexa");
    					}
    				}
    				var mainContainer = $("#ulto");
    				scrollToContainer = mainContainer.find('.toexa:last');
    				mainContainer.animate({
    					    scrollTop: scrollToContainer.offset().top - mainContainer.offset().top + mainContainer.scrollTop()
    					  }, 500);
    				if(data.taskNodeApprove[url3].approve_state == 2){
    					$("#tongguo").css({"background-color":"green","border-color":"green"});
    				};
    				if(data.taskNodeApprove[url3].approve_state == 3){
    					$("#butongguo").css({"background-color":"red","border-color":"red"});
    				}
    				if(data.taskNodeApprove[url3].approve_memo !=""){
    					$("#text").text(data.taskNodeApprove[url3].approve_memo);
    				};
    			}
        	});
        },
        anim:function(){
        	var mainContainer = $("#ulto");
			scrollToContainer = mainContainer.find('.toexa:last');
			mainContainer.animate({
				    scrollTop: scrollToContainer.offset().top - mainContainer.offset().top + mainContainer.scrollTop()
				  }, 500);
        },
        check:function(_fileId){
        	var _data = {'fileId':_fileId};
        	App.ajax({
    			type : "POST",
    			url : App.getApiUrl("downloadURL"),
        		data:_data,
    			success : function(data) {
    				var url = data.download_url;
    				//vm.url=url;
    				$("#vid").attr("src",url);
    				$("#video").attr("src",url);
    				//window.location.reload();
    				//vm.loadUrl();
    				
    			}
    		});
        	
        },
		 fanhui:function(url,taskId){
            window.location.href = App.getBaseUrl() + url + "?taskId=" + taskId;
        },
	}
});